﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics.CodeAnalysis;
using ZR.Admin.WebApi.Extensions;
using ZR.Model.mes.md;
using ZR.Service.mes.md;
using ZR.Service.mes.md.IService;
using ZR.Service.MES.md.IService;

namespace ZR.Admin.WebApi.Controllers.mes.md
{

    [Route("mes/md/workline")]
    public class MdWorklineController : BaseController
    {
        IMdWorklineService worklineService;
        public MdWorklineController(IMdWorklineService worklineService)
        {
            this.worklineService = worklineService;
        }


        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="pageNum"></param>
        /// <param name="pageSize"></param>
        /// <param name="deviceCode"></param>
        /// <param name="deviceName"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public IActionResult List(int pageNum, int pageSize, string lineCode = "", string lineName = "")
        {
            (int, List<MdWorkline>) data = worklineService.GetAll(lineCode, lineName, pageNum, pageSize);
            return ToResponse(new ApiResult(200, "success", data));
        }


        [HttpPost("addWorkline")]
        public IActionResult AddWorkline([FromBody] MdWorkline workline)
        {
            if (workline != null)
                workline.ToCreate(HttpContext);
            int result = worklineService.AddWorkline(workline);
            return SUCCESS(result);
        }

        [HttpPost("updateWorkline")]
        public IActionResult UpdateWorkline([FromBody] MdWorkline workline)
        {
            if (workline != null)
            {
                workline.ToUpdate(HttpContext);
            }

            int result = worklineService.UpdateWorkline(workline);
            return SUCCESS(result);
        }


        [HttpPost("delWorkline")]
        public IActionResult DelWorkline([FromBody] List<int> ids)
        {
            if (ids != null)
            {
                int result = worklineService.deleteWorkline(ids.ToArray());
                return ToResponse(result);
            }
            return null;

        }

       
        [HttpGet("getWorkshopList")]
        public  IActionResult GetWorkshopList(int worklineId=0)
        {
            List<MdWorkshop> MdWorkshopList= worklineService.GetMdWorkshops(worklineId);
            return SUCCESS(MdWorkshopList);
        }




    }
}
